    package com.bdqn.tour.dao.impl;

    import com.bdqn.tour.dao.BaseDao;
    import com.bdqn.tour.dao.HzyInfoDao;
    import com.bdqn.tour.pojo.User;


    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;

    public class HzyInfoDaoImpl extends BaseDao implements HzyInfoDao {
        @Override
        public List<User> getUserInfo(String phone) {
            List<User> list = new ArrayList<>();
            conn = getConnection();
            String sql = "select * from user where ipone = ?";
            try {
                psmt = conn.prepareStatement(sql);
                rs = executeQuery(sql, phone);
                while (rs.next()) {
                    User user = new User();
                    user.setUsername(rs.getString("username"));
                    user.setIpone(rs.getString("ipone"));
                    user.setEmail(rs.getString("email"));
                    user.setNickname(rs.getString("nickname"));
                    user.setSex(rs.getString("sex"));
                    user.setCareer(rs.getString("career"));
                    user.setQq(rs.getString("qq"));
                    list.add(user);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                closeAll(conn, psmt, rs);
            }
            return list;
        }

        @Override
        public boolean updateUserInfo(User user) {
            conn = getConnection();
            String sql = "update user set email = ?, nickname = ?, sex = ?, career = ?, qq = ? where ipone = ?";

            try {
                psmt = conn.prepareStatement(sql);
                psmt.setString(1, user.getEmail());
                psmt.setString(2, user.getNickname());
                psmt.setString(3, user.getSex());
                psmt.setString(4, user.getCareer());
                psmt.setString(5, user.getQq());
                psmt.setString(6, user.getIpone());

                int result = psmt.executeUpdate();
                System.out.println("SQL执行结果: " + result);
                return result > 0;

            } catch (SQLException e) {
                e.printStackTrace();
                return false;
            } finally {
                closeAll(conn, psmt, rs);
            }
        }
    }
